<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 
<%@page import="com.yc.comm.Constant"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String strUserRoleName = (String)session.getAttribute(Constant.USER_ROLE);
String strUserName = (String)session.getAttribute(Constant.USER_NAME);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">    
    <link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/ext-all.css">  
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/edit-grid.css">  
	<script type="text/javascript" src="<%=path%>/js/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/DWRTreeLoader.js"></script> 
	<script type="text/javascript" src="<%=path%>/js/ext/SearchField.js"></script>
	<script type='text/javascript' src="<%=path%>/dwr/interface/JCommWeb.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/query-dwr-proxy.js"></script>	 
	<script type='text/javascript' src='/btsm/dwr/interface/JGeographicalenvWeb.js'></script>
	<script type='text/javascript' src='/btsm/dwr/engine.js'></script>
	<script type='text/javascript' src='/btsm/dwr/util.js'></script>	

  </head>
  
<body>
<form id="deForm" action="<%=path%>/pages/station/environment.jsp" method="POST">
	<input type="hidden" name="btsname" id="btsnameID">
	<input type="hidden" name="btscode" id="btscodeID">
	<input type="hidden" name="ToPage" id="ToPageID">
</form>

    <div id="mainDiv" style="width:100%;height:100%"/>
<script type="text/javascript">
var ds;
var isAdd = true;
var btsFirstNo;
function loadBtsCodeData(ds,btsCode){
	ds.on('beforeload', function() 
	{
		ds.baseParams = {'<%=Constant.BTS_CODE%>':btsCode};
	});
	ds.load({params:{'<%=Constant.BTS_CODE%>':btsCode}});			
}


Ext.onReady(function(){
	Ext.QuickTips.init(); 
	Ext.form.Field.prototype.msgTarget = 'side'; 
	var viewport = new Ext.Viewport({
		layout:'border',
		frame:true,
		items:[ 
			{
				region: 'center',
				contentEl: 'mainDiv',
				margins:'110 5 30 5',
				split: true,
				border: true	
			}]
		});
	var sm = new Ext.grid.CheckboxSelectionModel({
				singleSelect: true,
				listeners:{
                         //单选事件
                        "rowselect":function(sm, row, rec)
                        {    
							var canEdit = rec.get("canEdit");
							if(canEdit === '<%=Constant.EDIT_YES%>' )
								btnEdit.enable(); 
							else
								btnEdit.disable();     
                        }  
                   } 
				});	
	var recordType = Ext.data.Record.create([								
							   {name: 'id', type: "string"},
							   {name: 'btscode', type: "string"},
							   {name: 'btsname', type: "string"},
							   {name: 'btszone', type: "string"},
							   {name: 'landform', type: "string"},
							   {name: 'lng', type: "string"},
							   {name: 'lat', type: "string"},
							   {name: 'relocationrd', type: "string"},
							   {name: 'username', type: "string"},
							   {name: 'distcode', type: "string"},
							   {name: 'btslevel', type: "string"},
							   {name: 'workingradius', type: "string"},
							   {name: 'memo', type: "string"},
							   {name: 'graphDeatilAddr', type: "string"},
							   {name: 'graphHigh', type: "string"},
							   {name: 'trannetid', type: "string"},
							   {name: 'trannetname', type: "string"},
							   {name: 'trannetgrade', type: "string"},
							   {name: 'btskind', type: "string"},
							   {name: 'btstype', type: "string"},
							   {name: 'coverage', type: "string"},
							   {name: 'maintype', type: "string"},
							   {name: 'canEdit', type: "string"}, 
							   {name: 'refreshtime', type: 'date', dateFormat: 'Y/m/d'}
						 ]);

	var cm  = new Ext.grid.ColumnModel(
			[
				sm, 
				{header: "基站编号", width:60,  sortable: true, dataIndex: 'btscode',align:'left'},
				{header: "基站名称", width:90,  sortable: true, dataIndex: 'btsname',align:'left'},
				{header: "位置区域", width:80,  sortable: true, dataIndex: 'btszone',align:'left'},	
				{header: "基站地形", width:70,  sortable: true, dataIndex: 'landform',align:'left'},	
				{header: "搬迁记录", width:80,  sortable: true, dataIndex: 'relocationrd',align:'left'},	
				{header: "维护人",  width:80,sortable: true, dataIndex: 'username',align:'left'},	
				{header: "所属地区", width:80, sortable: true, dataIndex: 'distcode',align:'left'},
				{header: "基站级别", width:70,  sortable: true, dataIndex: 'btslevel',align:'left'},
				{header: "有效工作半径",width:80,  sortable: true, dataIndex: 'workingradius',align:'left'},
				{header: "数据更新时间",width:80, sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d'),dataIndex: 'refreshtime',align:'left'},
				{header: "详细", width:50,sortable: false, dataIndex: 'id',renderer: showOperation},
				{header: "删除", width:50,sortable: false, dataIndex: 'id',renderer: showDelete}				
			]
		);
	function showOperation(value, cellmeta, record, rowIndex, columnIndex, store)
	{
		var btscode = record.get("btscode");
		var btsname = record.get("btsname");
		var canEdit = record.get("canEdit");
		if(canEdit === '<%=Constant.EDIT_YES%>' )
			return "<input type='button' value='详细' class='x-btn button' onclick='doEdit(\"" + btscode  +   "\",\""+btsname+"\")'>";  
		else
			return "---";	
	}	
		
	function showDelete(value, cellmeta, record, rowIndex, columnIndex, store)
	{
		var id = record.get("btscode");
		var canEdit = record.get("canEdit");
		if(canEdit === '<%=Constant.EDIT_YES%>' )
			return "<input type='button' value='删除' class='x-btn button' onclick='doDel(\"" + id  +   "\")'>";  
		else
			return "---";	
	}
	
	ds = new Ext.data.Store({
        proxy: new Ext.data.DWRProxy(JGeographicalenvWeb.getAllStationList, true),	
        reader: new Ext.data.ListRangeReader({
            totalProperty: 'totalSize',
            id: 'id'
        }, recordType),
        sortInfo:{field:'id', direction:'ASC'}// 排序信息
    });
	
	
		
	var btscodeField = new Ext.form.TextField({
			 id:'btscodeId',
			 fieldLabel:'基站编号',
			 emptyText:'基站编号',
			 name : 'btscode',
			 width : 200,
			 allowBlank : false,
			 blankText : '请输入基站编号',
			// maskRe : new RegExp('[a-zA-Z0-9]', 'gi')
			 itemCls:'win-first',
			 clearCls:'allow-float'
		});
	var btsNameField = new Ext.form.TextField({ 
			 id:'btsnameId',
			 fieldLabel:'基站名称',
			 emptyText:'基站名称',
			 name : 'btsname',
			 width : 200,
			 allowBlank : false,
			 blankText : '请输入基站名称'
		});	
	
	function createStation(){	
		var data = {};
		var record = new Ext.data.Record(data);
		stationWindow.show();
		stationWindow.formPanel.getForm().loadRecord(record);
		btscodeField.enable();
		btsNameField.enable();
		btsCodeButton.disable();	
		isAdd = true;		
	}
	function editStation(){
		var record = grid.getSelectionModel().getSelected();
		if(!record)
		{
			Ext.Msg.alert("提示","请先选择需要修改的基站 !");
			return;
		}  
		stationWindow.show();
		stationWindow.formPanel.getForm().loadRecord(record);
		btscodeField.disable();
		btsNameField.disable();
		btsCodeButton.enable();
		isAdd = false;
		btsFirstNo = record.get("btscode");
	}
	
	var btnAdd = new  Ext.Button({
					text:'新建',
					pressed:true,					 
					handler:createStation
				});
	var btnEdit = new  Ext.Button({
					text:'修改',
					pressed:true,					 
					handler:editStation
				});	

	btnEdit.disable();
	
	var contentDiv = Ext.get("mainDiv");
	var grid = new Ext.grid.GridPanel({
	    	el: 'mainDiv',	    	
	        ds: ds,
	        cm: cm,
			sm:sm,
			//title: '用户列表',
		    width: contentDiv.getComputedWidth(),
			height: contentDiv.getComputedHeight(), 
	        frame:true,
	        collapsible:false, 
	        enableDragDrop:false, 
			tbar: [
				'查询: ', ' ',
				new Ext.ux.form.SearchField({
						store:ds,
						width:320
					}), 
			
				btnAdd,
				'-',
				btnEdit
				],
			bbar: new Ext.PagingToolbar({
			        pageSize: 17,
			        store: ds,
			        displayInfo: true,
			        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
			        emptyMsg: "没有记录"
			    })
					
				
	    });
	    
	
    grid.render(); 
	ds.on('beforeload', function() {
		  ds.baseParams = {
				'<%=Constant.USER_ROLE%>':'<%=strUserRoleName%>',
				'<%=Constant.USER_ID%>':'<%=strUserName%>'
				 
		  };
		});		
	
	ds.load({params:{start:0,limit:17}});
	  
	ds.on('load', function() {
		   grid.getSelectionModel().selectFirstRow(); 
		});		
	//sm.on('rowselect',funciton(){
		//var rec = grid.getSelectionModel().getSelected();
		//alert(rec.get("id"));
	//})
	
	
	var btszoneStore  = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    }); 
	
	var btszoneCombo = new Ext.form.ComboBox({	   
		fieldLabel: '基站位置区域',
		name: 'btszone',	
		width:200,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'请选基站位置区域',
		emptyText:'选择基站位置区域',
		hiddenName:'btszone',
		triggerAction: 'all',
		allowBlank:false,
		editable:false, 
		store: btszoneStore
	});
	btszoneStore.on('beforeload', function() {
			  btszoneStore.baseParams = {
					DIRECTORY_TYPE:'01'   
			  };
		});	
	btszoneStore.load({params:{DIRECTORY_TYPE:'01'}});
	
	
	var landformStore  = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    }); 
	
	var landformCombo = new Ext.form.ComboBox({	   
		fieldLabel: '基站地形',
		name: 'landform',	
		width:200,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'请选基站地形',
		emptyText:'选择基站地形',
		hiddenName:'landform',
		triggerAction: 'all',
		allowBlank:false,
		editable:false, 
		store: landformStore
	});
	landformStore.on('beforeload', function() {
			  landformStore.baseParams = {
					DIRECTORY_TYPE:'02'   
			  };
		});	
	landformStore.load({params:{DIRECTORY_TYPE:'02'}});
	
	
	var distcodeStore  = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.scdqxslist,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    }); 
	var distcodeCombo = new Ext.form.ComboBox({	   
		fieldLabel: '所属地区',
		name: 'distcode',	
		width:200,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'请选所属地区',
		emptyText:'选择所属地区',
		hiddenName:'distcode',
		triggerAction: 'all',
		allowBlank:false,
		editable:true, 
		store: distcodeStore
	});
	distcodeStore.load({});
	
	var btslevelStore = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    }); 
			
	var queryTypeData = [['0', '0'],['1', '1'],['2', '2'],['3', '3'],['4', '4'],['5', '5'],['6', '6'],['7', '7'],['8', '8'],['9', '9']];
        
	var btslevelStore = new Ext.data.SimpleStore({
		    fields: ['value', 'text'],
		    data : queryTypeData
		});		
			
	var btslevelCombo = new Ext.form.ComboBox({	   
		fieldLabel: '基站级别',
		name: 'btslevel',	
		width:200,
		valueField :"value",
	    displayField: "text",
	    mode: 'local',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'请选基站级别',
		emptyText:'选择基站级别',
		hiddenName:'btslevel',
		triggerAction: 'all',
		allowBlank:false,
		editable:false, 
		store: btslevelStore,
		value:-1
	}); 
	
	var netGradeStore  = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    }); 
	
	var netGradeCombo = new Ext.form.ComboBox({	   
		fieldLabel: '网元级别',
		name: 'trannetgrade',	
		width:200,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'网元级别',
		emptyText:'网元级别',
		hiddenName:'trannetgrade',
		triggerAction: 'all',
		//allowBlank:false,
		editable:false, 
		store: netGradeStore
	});
	netGradeStore.on('beforeload', function() {
			  netGradeStore.baseParams = {
					DIRECTORY_TYPE:'30'   
			  };
		});	
	netGradeStore.load({params:{DIRECTORY_TYPE:'30'}});
	
	var btskindStore  = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    }); 
	
	var btskindCombo = new Ext.form.ComboBox({	   
		fieldLabel: '基站性质',
		name: 'btskind',	
		width:200,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'基站性质',
		emptyText:'基站性质',
		hiddenName:'btskind',
		triggerAction: 'all',
		editable:false, 
		store: btskindStore
	});
	btskindStore.on('beforeload', function() {
			  btskindStore.baseParams = {
					DIRECTORY_TYPE:'31'   
			  };
		});	
	//btskindStore.load({params:{DIRECTORY_TYPE:'31'}});
	var btstypeStore  = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    });
	var btstypeCombo = new Ext.form.ComboBox({	   
		fieldLabel: '基站类型',
		name: 'btstype',	
		width:200,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'基站类型',
		emptyText:'基站类型',
		hiddenName:'btstype',
		triggerAction: 'all',
		editable:false, 
		store: btstypeStore
	});
	btstypeStore.on('beforeload', function() {
			  btstypeStore.baseParams = {
					DIRECTORY_TYPE:'19'   
			  };
		});	
	var coverageStore  = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    });
	var coverageCombo = new Ext.form.ComboBox({	   
		fieldLabel: '覆盖区域',
		name: 'coverage',	
		width:200,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'覆盖区域',
		emptyText:'覆盖区域',
		hiddenName:'coverage',
		triggerAction: 'all',
		editable:false, 
		store: coverageStore
	});
	coverageStore.on('beforeload', function() {
			  coverageStore.baseParams = {
					DIRECTORY_TYPE:'32'   
			  };
		});	
	
	var maintypeStore  = new Ext.data.Store({  
		        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
		        reader:new Ext.data.DWRArrayReader(
						{},
						new Ext.data.Record.create([  
							{name: 'text', mapping:1},       
							{name: 'value',mapping:0}                   
						  ])
						)  
		    });
	var maintypeCombo = new Ext.form.ComboBox({	   
		fieldLabel: '维护方式',
		name: 'maintype',	
		width:200,
		valueField :"value",
	    displayField: "text",
	    mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'维护方式',
		emptyText:'维护方式',
		hiddenName:'maintype',
		triggerAction: 'all',
		editable:false, 
		store: maintypeStore
	});
	maintypeStore.on('beforeload', function() {
			  maintypeStore.baseParams = {
					DIRECTORY_TYPE:'17'   
			  };
		});	
	
	var cType = Ext.data.Record.create([								
							   {name: 'id', type: "string"},
							   {name: 'btscode', type: "string"}, 
							   {name: 'other', type: "string"}, 
							   {name: 'btsCodeNo',  type: 'string'}
						 ]); 
	var cSM = new Ext.grid.CheckboxSelectionModel({singleSelect: true});						
	var cCM = new Ext.grid.ColumnModel(
			[    
				//{header: "id", width: 50,dataIndex: 'id',align:'left'},
				cSM, 	
				{header: "编号", width: 130, dataIndex: 'other',align:'left'},	
				{header: "基站编号", width: 100, dataIndex: 'btsCodeNo',align:'left',editor: new Ext.form.TextField({allowBlank: false})}				
			]
		);				 
	
	function showCDelete(id)
	{
		//return "<input type='button' value='删除' class='x-btn button' onclick='doStorageBatteryDelete(\"" + id  +   "\")'>";  
	}
	var cDS = new Ext.data.Store({
				proxy: new Ext.data.DWRProxy(JGeographicalenvWeb.getNoList, true),	
				reader: new Ext.data.ListRangeReader({
					totalProperty: 'totalSize',
					id: 'id'
				}, cType),
				sortInfo:{field:'id', direction:'ASC'}// 排序信息
			});
		 
	var cGrid = new Ext.grid.EditorGridPanel({			 	
			ds: cDS,
			cm: cCM, 
			autoWidth : true,  
			autoScroll : true,  
			autoHeight　: false,
			region : 'center',
			width:200,
			height: 250,
			minSize: 200,		
			frame:true,
			clicksToEdit:2,
			sm: cSM,
			tbar: [
				{
					text: '添加',
					iconCls: 'silk-add',
					handler: onAdd
				}, 
				'-', 
				{
					text: '删除',
					iconCls: 'silk-delete',
					handler: onDelete
				}, 
				'-'
			],
				
			bbar: new Ext.PagingToolbar({
					pageSize: 17,
					store: cDS,
					displayInfo: true,
					displayMsg: '一共 {2} 条',
					emptyMsg: "没有记录"
				})
		});

	function len(s) { 
		var l = 0; 
		var a = s.split(""); 
		for (var i=0;i<a.length;i++) { 
			if (a[i].charCodeAt(0)<299) { 
				l++; 
			} else { 
				l+=2; 
			} 
		} 
		return l; 
	} 	
		
	// 单元格编辑后事件处理
	cGrid.on("afteredit", afterEdit, cGrid);
	// 事件处理函数
	function afterEdit(e) {
		var record = e.record;
        var GeograpNoBO = {};
		var btsCodeNo = record.get("btsCodeNo");
		if(len(btsCodeNo)>12)
		{
			Ext.Msg.show({
                title: '提示',
                msg: '基站编号的长度不能大于12。',
                modal: false,
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
			record.set(e.field, e.originalValue);
			return false;
		}
		
		GeograpNoBO.id = record.get("id");
		GeograpNoBO.btscode = btsFirstNo;
		GeograpNoBO.other = record.get("other");
		GeograpNoBO.btsCodeNo = btsCodeNo;
		JGeographicalenvWeb.saveGeographicalenvNoBo(GeograpNoBO,function(data){
  	     	loadBtsCodeData(cDS,grid.getSelectionModel().getSelected().get("btscode"));		
        });
	};
		
		
	/**
     * onAdd
     */
    function onAdd(btn, ev) {        
		var Plant = cGrid.getStore().recordType;	
		var TotalCount = cGrid.getStore().getTotalCount()+1;
		var p = new Plant({
                    //id : '',
					btscode : "基站编号"+TotalCount,
					btsCodeNo : ""
                });

		cGrid.stopEditing();	
        cGrid.store.insert(0, p);      
		cGrid.startEditing(0, 0);
		
		
		var GeograpNoBO = {};// 
		GeograpNoBO.btscode = btsFirstNo;
		GeograpNoBO.btsCodeNo = "";
		GeograpNoBO.other = "基站编号"+TotalCount;
		JGeographicalenvWeb.saveGeographicalenvNoBo(GeograpNoBO,function(data){
  	     	loadBtsCodeData(cDS,grid.getSelectionModel().getSelected().get("btscode"));		
        });
		
		
    }
    /**
     * onDelete
     */
    function onDelete() {
        var rec = cGrid.getSelectionModel().getSelected();
        if (!rec) {
			Ext.Msg.show({
                title: '提示',
                msg: '请选择需要删除的基站编号后，再点击删除按钮。',
                modal: false,
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });

            return false;
        }      
		var GeograpNoBO = {};
		GeograpNoBO.id = rec.get("id");		
		JGeographicalenvWeb.deleteGeographicalenvNoBo(GeograpNoBO,function(data){
  	     	loadBtsCodeData(cDS,grid.getSelectionModel().getSelected().get("btscode"));		
			cGrid.store.remove(rec);
        });
    }
	
	
	//选择父节点弹出窗口
	var win = new Ext.Window({
					//el:'hello-win',
					layout:'fit',
					width:350,
					height:300,
					closeAction:'hide',
					plain: true,
					modal:true,
					items:cGrid,		
					buttons: [
						{
							text:'确&nbsp;&nbsp;定',
							handler: function()
							{								 
								win.hide();
							}
						}]
				});	
	var btsCodeButton = new Ext.Button({
						pressed : true,
	                    enableToggle : true,
	                    text : '其他编号',
	                    toggleHandler:doShow
			});
	btsCodeButton.disable();	
		
	function doShow()
	{	        
		win.show();  
		loadBtsCodeData(cDS,grid.getSelectionModel().getSelected().get("btscode"));			
	}
	
	

	
	var statForm = new Ext.FormPanel({
	    	labelAlign: 'right',
	        frame:true,	        
	        labelWidth:80,	       
			anchor:'90%',
			height:550,		
			buttonAlign:'right', 
			border: false,
			layout:'column',
			margins:'35 35 35 35',	
	        items: [ 
					{
					columnWidth:.33,
					layout: 'form',  
					labelWidth:100,	 
					labelAlign:'right',		
					items: [
						btscodeField, 
						btsCodeButton,
						landformCombo
						,{
							xtype:'textfield',
							fieldLabel: '基站搬迁记录',
							width:200,
							name: 'relocationrd'
						}, {
							xtype:'hidden',
							fieldLabel: '维护人',
							width:200,
							value:'<%=strUserName%>',
							name: 'username'
						}, {
							xtype:'numberfield',
							fieldLabel: '有效工作半径（米）',
							width:200,
							value:-1,
							name: 'workingradius'
						}, {
							xtype:'textfield',
							fieldLabel: '传输网元ID',
							width:200,
							name: 'trannetid'
						}, {
							xtype:'textfield',
							fieldLabel: '传输网元名称',
							width:200,
							name: 'trannetname'
						},
						netGradeCombo
						, {
							xtype: 'textfield',     
				            fieldLabel: '基站图片',     
				            name: 'stationpicture',     
				            inputType: 'file',   
				            height:20,
				            width:200,
				            allowBlank: false,     
				            blankText: '文件不能为空.'  
						}
						]
				 },
				 {
					columnWidth:.33,
					layout: 'form',  
					labelWidth:80,	
					labelAlign:'right',				
					items: [
						btsNameField
						, {
							xtype:'numberfield',
							decimalPrecision:6,
							fieldLabel: '经度',
							allowBlank:false,
							width:200,
							name: 'lng'
						}, {
							xtype:'textfield',
							fieldLabel: '基站详细地址',
							width:200,
							name: 'graphDeatilAddr'
						},{
							xtype:'datefield',
							fieldLabel: '入网时间',
							format : "Y-m-d",
							width:200,
							allowBlank:false,
							name: 'registtime'
						}, 
						 btskindCombo
						,btstypeCombo
						,
						{
							xtype:'textarea',
							fieldLabel: '备注',
							width:200,
							name: 'memo'
						}]
				 },
				 {
					columnWidth:.34,
					layout: 'form',  
					labelWidth:80,	 
					labelAlign:'right',		
					items: [
						btszoneCombo, 
						{
							xtype:'numberfield',
							decimalPrecision:6,
							fieldLabel: '纬度',
							width:200,
							allowBlank:false,
							name: 'lat'
						}, 
						distcodeCombo
						,
						{
							xtype:'numberfield',
							fieldLabel: '海拨高度(米)',
							width:200,
							value:-1,
							name: 'graphHigh'
						},btslevelCombo
						,coverageCombo
						,maintypeCombo
						]
				 } 
				]
		});
		
	var StationWindow = function() {
		var _win = this;
		this.formPanel = statForm;
		var _form = this.formPanel.getForm();
		StationWindow.superclass.constructor.call(this, { 
			title: '新建基站',
			width : 980,
			height : 350,
			resizable : true,
			plain : false,
			border : false,
			modal : true,
			autoScroll : false,
			layout : 'fit',
			closeAction : 'hide',
			items : this.formPanel,
			buttonAlign:'center',
			buttons : 
			[
				{	
					text : ' 保存',
					handler :  function(){
						if (!_form.isValid())
							return;	
							
						var form = _form.getValues(false);	
						GeographicalenvBo = {};
						GeographicalenvBo.btscode = form.btscode;
						GeographicalenvBo.btsname = form.btsname;
						GeographicalenvBo.btszone = form.btszone;
						GeographicalenvBo.landform = form.landform;
						GeographicalenvBo.lng = form.lng;
						GeographicalenvBo.lat = form.lat;
						GeographicalenvBo.relocationrd = form.relocationrd;
						GeographicalenvBo.username = form.username;
						GeographicalenvBo.distcode = form.distcode;
						GeographicalenvBo.btslevel = form.btslevel;
						GeographicalenvBo.workingradius = form.workingradius;
						GeographicalenvBo.graphHigh = form.graphHigh;
						GeographicalenvBo.memo = form.memo;
						GeographicalenvBo.graphDeatilAddr = form.graphDeatilAddr;
						
						
						GeographicalenvBo.trannetid = form.trannetid;
						GeographicalenvBo.trannetname = form.trannetname;
						GeographicalenvBo.trannetgrade = form.trannetgrade;
						GeographicalenvBo.btskind = form.btskind;
						GeographicalenvBo.btstype = form.btstype;
						GeographicalenvBo.coverage = form.coverage;
						GeographicalenvBo.maintype = form.maintype;
						
						var registtimeDate = new Date();	
						var arrPlanTime = form.registtime.split("-");		
								
						var yearOth = arrPlanTime[0];
						var monthOth = arrPlanTime[1];
						var dayOth = arrPlanTime[2];
						registtimeDate.setFullYear(yearOth,monthOth-1,dayOth);
						
						GeographicalenvBo.registtime = registtimeDate;
						 
						if(isAdd)
						{
							JGeographicalenvWeb.saveGeographicalenvBo(GeographicalenvBo,function(data)
							{
								if(data)
								{ 								
									Ext.Msg.alert('成功',"操作成功！",function(){
										_win.hide();
										ds.load({params:{start:0,limit:17}});
									}); 				 
								}else
								{
									Ext.Msg.alert("失败","操作失败!");
								}
							})
						}else{
							var record = grid.getSelectionModel().getSelected()
							GeographicalenvBo.btscode = record.get("btscode");
							GeographicalenvBo.btsname = record.get("btsname");
							JGeographicalenvWeb.updateGeographicalenv(GeographicalenvBo,function(data)
							{
								if(data)
								{ 								
									Ext.Msg.alert('成功',"操作成功！",function(){
										_win.hide();
										ds.load({params:{start:0,limit:17}});
									}); 				 
								}else
								{
									Ext.Msg.alert("失败","操作失败!");
								}
							})
						}
					
					}
				},{
					text : '取消',
					handler : function() {
						_win.hide();
						_form.reset();
					},
					tooltip : '关闭对话框'
				}
			]	
		});
	}
	Ext.extend(StationWindow, Ext.Window); 
	var stationWindow = new StationWindow();	
		
	function saveGeographicalenv()
	{
		
		
		
	}	
		
})	

function doEdit(btsCode,btsName){
	document.getElementById("btscodeID").value = btsCode; 
	document.getElementById("btsnameID").value = btsName; 
	//document.getElementById("deForm").action = "<%=path%>/pages/fiber/SectionDetailInfo.jsp";
	document.getElementById("deForm").submit();
}	
function doDel(btsCode){
	JGeographicalenvWeb.deleteGeographicalenvBo(btsCode,function(data)
	{
		if(data)
		{ 								
			Ext.Msg.alert('成功',"操作成功！",function(){				 
				ds.load({params:{start:0,limit:17}});
			}); 				 
		}else
		{
			Ext.Msg.alert("失败","操作失败!");
		}
	})
}

</script>
</body>
</html>
